
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <stdio.h>
int main()
{

int fd[2];
int * write_fd = &fd[1];	//读写指针
int * read_fd = &fd[0];
char msg[] = "son speaking";	//管道要传送的信息
char readbuffer[80];		//缓冲区
int tube = pipe(fd);		//建立管道
if(tube == -1)			//判断管道创建成功否
{
printf("error , tube failed\n");
}

pid_t pidf = getppid();		//获取父进程的ID
printf("pid: %d \n",pidf);

pid_t pids = fork();		//创建子进程
if(pids < 0)			//判断进程创建成功与否
printf("error , fork fail\n");
if(pids == 0)			//子进程创建成功且在执行
{
close(*read_fd);		//关闭读出端
tube = write(*write_fd,msg,strlen(msg));	//从写入端写入
printf("here is son running , give father a msg : son speaking .\n");
return 0;
}else				//父进程在执行
{
close(* write_fd);		//关闭写入端
tube = read(*read_fd,readbuffer,sizeof(readbuffer)-1);		//读出管道信息
printf("here is father , while the kid id is %d \n",pids);
printf("son' msg : %s\n",readbuffer);
}

}
